package 剑指offer;

/**
 * 题目描述
 * 请实现一个函数用来找出字符流中第一个只出现一次的字符。
 *
 * @author Administrator
 */
public class 字符流中第一个只出现一次的字符 {
    int[] hashtable = new int[256];
    StringBuffer s = new StringBuffer();

    //Insert one char from stringstream
    public void Insert(char ch) {
        s.append(ch);
        if (hashtable[ch] == 0)
            hashtable[ch] = 1;
        else hashtable[ch] += 1;
    }

    //return the first appearence once char in current stringstream
    public char FirstAppearingOnce() {
        char[] str = s.toString().toCharArray();
        for (char c : str) {
            if (hashtable[c] == 1)
                return c;
        }
        return '#';
    }
}

